package com.bluefoxyu.controller;


import com.bluefoxyu.domain.dto.AdminDTO;
import com.bluefoxyu.domain.dto.StudentAddDTO;
import com.bluefoxyu.domain.entity.Student;
import com.bluefoxyu.domain.result.Result;
import com.bluefoxyu.domain.vo.AdminVO;
import com.bluefoxyu.mapper.StudentMapper;
import com.bluefoxyu.service.IAdminService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 管理员信息表 前端控制器
 * </p>
 *
 * @author bluefoxyu
 * @since 2024-06-16
 */
@RestController
@RequestMapping("/admin")
@RequiredArgsConstructor
@Tag(name ="管理页面学生接口")
public class AdminController {

    private final StudentMapper studentMapper;
    private final IAdminService adminService;

    @Operation(summary = "管理员登录")
    @PostMapping("/login")
    public Result<AdminVO> login(@RequestBody AdminDTO adminDTO) {
        return Result.success(adminService.login(adminDTO));
    }

    @Operation(summary = "添加学生基本信息")
    @PutMapping("/addStudent")
    public Result<String> addStudent(@RequestBody StudentAddDTO studentAddDTO) {
        adminService.addStudent(studentAddDTO);
        return Result.success("添加成功");
    }

    /**
     * 根据学生id删除学生基本信息
     * @param ids 学生ids集合
     */
    @Operation(summary = "根据学生ids集合删除学生基本信息")
    @DeleteMapping("/deleteStudentByIds")
    public Result<String> deleteStudentByIds(@RequestParam List<Integer> ids) {
        adminService.deleteByIds(ids);
        return Result.success("删除成功");
    }

    @Operation(summary = "更新学生基本信息")
    @PostMapping("/updateStudent")
    public Result<String> updateStudent(@RequestBody Student student) {
        studentMapper.updateById(student);
        return Result.success("更新成功");
    }


    @Operation(summary = "查询所有学生基本信息")
    @GetMapping("/getAllStudents")
    public Result<List<Student>> getAllStudents() {
        return Result.success(studentMapper.selectList(null));
    }

}
